package xml_tests.xmlJTreeView;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;

public class XmlToJTreeMain extends JFrame {
	private JPanel jContentPane = null;
	JPanel panel;

	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);

			JButton btnGenerate = new JButton("Generate");
			btnGenerate.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					SaxParser sp = new SaxParser("catalog.xml");
					JTree jt = new JTree(ObjectModelToTreeModel.getTreeOfModel(sp.getBookL()));
					JScrollPane jp = new JScrollPane(jt);

					jp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
					jp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
					jp.setBounds(2, 4, 500, 300);
					panel.add(jp);
					panel.revalidate();
					panel.repaint();
				}
			});
			btnGenerate.setBounds(334, 11, 89, 23);
			jContentPane.add(btnGenerate);
			panel = new JPanel();
			panel.setBounds(10, 11, 314, 290);
			panel.setLayout(null);
			jContentPane.add(panel);

		}
		return jContentPane;
	}

	public XmlToJTreeMain() {
		super();
		setSize(441, 350);
		setContentPane(getJContentPane());
		setTitle("JFrame");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}

	public static void main(String[] args) {
		new XmlToJTreeMain();
	}
}
